

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>describe.core.system &mdash; describe 0.1.0 documentation</title>
  

  
  
  
  

  

  
  
    

  

  <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/css/style.css" type="text/css" />
    <link rel="author" title="About these documents" href="../../../about.html" />
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" /> 

  
  <script src="../../../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../../../index.html" class="icon icon-home"> describe
          

          
          </a>

          
            
            
              <div class="version">
                0.1.0
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul>
<li class="toctree-l1"><a class="reference internal" href="../../../install.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../tutorials/tutorials.html">Tutorials</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../doc/modules.html">Documentation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../about.html">About</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../index.html">describe</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../../index.html">Module code</a> &raquo;</li>
        
      <li>describe.core.system</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for describe.core.system</h1><div class="highlight"><pre>
<span></span><span class="kn">from</span> <span class="nn">__future__</span> <span class="k">import</span> <span class="n">absolute_import</span><span class="p">,</span> <span class="n">division</span><span class="p">,</span> <span class="n">print_function</span>
<span class="kn">from</span> <span class="nn">builtins</span> <span class="k">import</span> <span class="nb">super</span>
<span class="kn">from</span> <span class="nn">ase</span> <span class="k">import</span> <span class="n">Atoms</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>


<div class="viewcode-block" id="System"><a class="viewcode-back" href="../../../doc/describe.core.html#describe.core.system.System">[docs]</a><span class="k">class</span> <span class="nc">System</span><span class="p">(</span><span class="n">Atoms</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Represents atomic systems that are used internally by the package.</span>
<span class="sd">    Inherits from the ase.Atoms class, but adds the possibility to cache</span>
<span class="sd">    various time-consuming quantities that can be shared when creating multiple</span>
<span class="sd">    descriptors.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span>
            <span class="bp">self</span><span class="p">,</span>
            <span class="n">symbols</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
            <span class="n">positions</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
            <span class="n">numbers</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
            <span class="n">tags</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
            <span class="n">momenta</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
            <span class="n">masses</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
            <span class="n">magmoms</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
            <span class="n">charges</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
            <span class="n">scaled_positions</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
            <span class="n">cell</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
            <span class="n">pbc</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
            <span class="n">celldisp</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
            <span class="n">constraint</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
            <span class="n">calculator</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
            <span class="n">info</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
            <span class="n">wyckoff_positions</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
            <span class="n">equivalent_atoms</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>

        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span>
            <span class="n">symbols</span><span class="p">,</span>
            <span class="n">positions</span><span class="p">,</span>
            <span class="n">numbers</span><span class="p">,</span>
            <span class="n">tags</span><span class="p">,</span>
            <span class="n">momenta</span><span class="p">,</span>
            <span class="n">masses</span><span class="p">,</span>
            <span class="n">magmoms</span><span class="p">,</span>
            <span class="n">charges</span><span class="p">,</span>
            <span class="n">scaled_positions</span><span class="p">,</span>
            <span class="n">cell</span><span class="p">,</span>
            <span class="n">pbc</span><span class="p">,</span>
            <span class="n">celldisp</span><span class="p">,</span>
            <span class="n">constraint</span><span class="p">,</span>
            <span class="n">calculator</span><span class="p">,</span>
            <span class="n">info</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">wyckoff_positions</span> <span class="o">=</span> <span class="n">wyckoff_positions</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">equivalent_atoms</span> <span class="o">=</span> <span class="n">equivalent_atoms</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_cell_inverse</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_displacement_tensor</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_distance_matrix</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_inverse_distance_matrix</span> <span class="o">=</span> <span class="kc">None</span>

<div class="viewcode-block" id="System.from_atoms"><a class="viewcode-back" href="../../../doc/describe.core.html#describe.core.system.System.from_atoms">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">from_atoms</span><span class="p">(</span><span class="n">atoms</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Creates a System object from ASE.Atoms object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">system</span> <span class="o">=</span> <span class="n">System</span><span class="p">(</span>
            <span class="n">symbols</span><span class="o">=</span><span class="n">atoms</span><span class="o">.</span><span class="n">get_chemical_symbols</span><span class="p">(),</span>
            <span class="n">positions</span><span class="o">=</span><span class="n">atoms</span><span class="o">.</span><span class="n">get_positions</span><span class="p">(),</span>
            <span class="n">tags</span><span class="o">=</span><span class="n">atoms</span><span class="o">.</span><span class="n">get_tags</span><span class="p">(),</span>
            <span class="n">momenta</span><span class="o">=</span><span class="n">atoms</span><span class="o">.</span><span class="n">get_momenta</span><span class="p">(),</span>
            <span class="n">masses</span><span class="o">=</span><span class="n">atoms</span><span class="o">.</span><span class="n">get_masses</span><span class="p">(),</span>
            <span class="n">magmoms</span><span class="o">=</span><span class="n">atoms</span><span class="o">.</span><span class="n">get_initial_magnetic_moments</span><span class="p">(),</span>
            <span class="n">charges</span><span class="o">=</span><span class="n">atoms</span><span class="o">.</span><span class="n">get_initial_charges</span><span class="p">(),</span>
            <span class="n">cell</span><span class="o">=</span><span class="n">atoms</span><span class="o">.</span><span class="n">get_cell</span><span class="p">(),</span>
            <span class="n">pbc</span><span class="o">=</span><span class="n">atoms</span><span class="o">.</span><span class="n">get_pbc</span><span class="p">(),</span>
            <span class="n">celldisp</span><span class="o">=</span><span class="n">atoms</span><span class="o">.</span><span class="n">get_celldisp</span><span class="p">(),</span>
            <span class="n">constraint</span><span class="o">=</span><span class="n">atoms</span><span class="o">.</span><span class="n">_get_constraints</span><span class="p">(),</span>
            <span class="n">calculator</span><span class="o">=</span><span class="n">atoms</span><span class="o">.</span><span class="n">get_calculator</span><span class="p">(),</span>
            <span class="n">info</span><span class="o">=</span><span class="n">atoms</span><span class="o">.</span><span class="n">info</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">system</span></div>

<div class="viewcode-block" id="System.get_cell_inverse"><a class="viewcode-back" href="../../../doc/describe.core.html#describe.core.system.System.get_cell_inverse">[docs]</a>    <span class="k">def</span> <span class="nf">get_cell_inverse</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get the matrix inverse of the lattice matrix.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cell_inverse</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_cell_inverse</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">inv</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_cell</span><span class="p">())</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cell_inverse</span></div>

<div class="viewcode-block" id="System.to_scaled"><a class="viewcode-back" href="../../../doc/describe.core.html#describe.core.system.System.to_scaled">[docs]</a>    <span class="k">def</span> <span class="nf">to_scaled</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">positions</span><span class="p">,</span> <span class="n">wrap</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Used to transform a set of positions to the basis defined by the</span>
<span class="sd">        cell of this system.</span>

<span class="sd">        Args:</span>
<span class="sd">            positions (numpy.ndarray): The positions to scale</span>
<span class="sd">            wrap (numpy.ndarray): Whether the positions should be wrapped</span>
<span class="sd">                inside the cell.</span>

<span class="sd">        Returns:</span>
<span class="sd">            numpy.ndarray: The scaled positions</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">fractional</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">solve</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">get_cell</span><span class="p">()</span><span class="o">.</span><span class="n">T</span><span class="p">,</span>
            <span class="n">positions</span><span class="o">.</span><span class="n">T</span><span class="p">)</span><span class="o">.</span><span class="n">T</span>

        <span class="k">if</span> <span class="n">wrap</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">periodic</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">pbc</span><span class="p">):</span>
                <span class="k">if</span> <span class="n">periodic</span><span class="p">:</span>
                    <span class="c1"># Yes, we need to do it twice.</span>
                    <span class="n">fractional</span><span class="p">[:,</span> <span class="n">i</span><span class="p">]</span> <span class="o">%=</span> <span class="mf">1.0</span>
                    <span class="n">fractional</span><span class="p">[:,</span> <span class="n">i</span><span class="p">]</span> <span class="o">%=</span> <span class="mf">1.0</span>

        <span class="k">return</span> <span class="n">fractional</span></div>

<div class="viewcode-block" id="System.to_cartesian"><a class="viewcode-back" href="../../../doc/describe.core.html#describe.core.system.System.to_cartesian">[docs]</a>    <span class="k">def</span> <span class="nf">to_cartesian</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">scaled_positions</span><span class="p">,</span> <span class="n">wrap</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Used to transofrm a set of relative positions to the cartesian basis</span>
<span class="sd">        defined by the cell of this system.</span>

<span class="sd">        Args:</span>
<span class="sd">            positions (numpy.ndarray): The positions to scale</span>
<span class="sd">            wrap (numpy.ndarray): Whether the positions should be wrapped</span>
<span class="sd">                inside the cell.</span>

<span class="sd">        Returns:</span>
<span class="sd">            numpy.ndarray: The cartesian positions</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">wrap</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">periodic</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">pbc</span><span class="p">):</span>
                <span class="k">if</span> <span class="n">periodic</span><span class="p">:</span>
                    <span class="c1"># Yes, we need to do it twice.</span>
                    <span class="n">scaled_positions</span><span class="p">[:,</span> <span class="n">i</span><span class="p">]</span> <span class="o">%=</span> <span class="mf">1.0</span>
                    <span class="n">scaled_positions</span><span class="p">[:,</span> <span class="n">i</span><span class="p">]</span> <span class="o">%=</span> <span class="mf">1.0</span>

        <span class="n">cartesian_positions</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">scaled_positions</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_cell</span><span class="p">())</span>
        <span class="k">return</span> <span class="n">cartesian_positions</span></div>

<div class="viewcode-block" id="System.get_displacement_tensor"><a class="viewcode-back" href="../../../doc/describe.core.html#describe.core.system.System.get_displacement_tensor">[docs]</a>    <span class="k">def</span> <span class="nf">get_displacement_tensor</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;A matrix where the entry A[i, j, :] is the vector</span>
<span class="sd">        self.cartesian_pos[i] - self.cartesian_pos[j].</span>

<span class="sd">        For periodic systems the distance of an atom from itself is the</span>
<span class="sd">        smallest displacement of an atom from one of it&#39;s periodic copies, and</span>
<span class="sd">        the distance of two different atoms is the distance of two closest</span>
<span class="sd">        copies.</span>

<span class="sd">        Returns:</span>
<span class="sd">            np.array: 3D matrix containing the pairwise distance vectors.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_displacement_tensor</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">pbc</span><span class="o">.</span><span class="n">any</span><span class="p">():</span>
                <span class="n">pos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_scaled_positions</span><span class="p">()</span>
                <span class="n">disp_tensor</span> <span class="o">=</span> <span class="n">pos</span><span class="p">[:,</span> <span class="kc">None</span><span class="p">,</span> <span class="p">:]</span> <span class="o">-</span> <span class="n">pos</span><span class="p">[</span><span class="kc">None</span><span class="p">,</span> <span class="p">:,</span> <span class="p">:]</span>

                <span class="c1"># Take periodicity into account by wrapping coordinate elements</span>
                <span class="c1"># that are bigger than 0.5 or smaller than -0.5</span>
                <span class="n">indices</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">disp_tensor</span> <span class="o">&gt;</span> <span class="mf">0.5</span><span class="p">)</span>
                <span class="n">disp_tensor</span><span class="p">[</span><span class="n">indices</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">-</span> <span class="n">disp_tensor</span><span class="p">[</span><span class="n">indices</span><span class="p">]</span>
                <span class="n">indices</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">disp_tensor</span> <span class="o">&lt;</span> <span class="o">-</span><span class="mf">0.5</span><span class="p">)</span>
                <span class="n">disp_tensor</span><span class="p">[</span><span class="n">indices</span><span class="p">]</span> <span class="o">=</span> <span class="n">disp_tensor</span><span class="p">[</span><span class="n">indices</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span>

                <span class="c1"># Transform to cartesian</span>
                <span class="n">disp_tensor</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">to_cartesian</span><span class="p">(</span><span class="n">disp_tensor</span><span class="p">)</span>

                <span class="c1"># Figure out the smallest basis vector and set it as</span>
                <span class="c1"># displacement for diagonal</span>
                <span class="n">cell</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_cell</span><span class="p">()</span>
                <span class="n">basis_lengths</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">cell</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
                <span class="n">min_index</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">argmin</span><span class="p">(</span><span class="n">basis_lengths</span><span class="p">)</span>
                <span class="n">min_basis</span> <span class="o">=</span> <span class="n">cell</span><span class="p">[</span><span class="n">min_index</span><span class="p">]</span>
                <span class="n">diag_indices</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">diag_indices</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">disp_tensor</span><span class="p">))</span>
                <span class="n">disp_tensor</span><span class="p">[</span><span class="n">diag_indices</span><span class="p">]</span> <span class="o">=</span> <span class="n">min_basis</span>

            <span class="k">else</span><span class="p">:</span>
                <span class="n">pos</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_positions</span><span class="p">()</span>
                <span class="n">disp_tensor</span> <span class="o">=</span> <span class="n">pos</span><span class="p">[:,</span> <span class="kc">None</span><span class="p">,</span> <span class="p">:]</span> <span class="o">-</span> <span class="n">pos</span><span class="p">[</span><span class="kc">None</span><span class="p">,</span> <span class="p">:,</span> <span class="p">:]</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">_displacement_tensor</span> <span class="o">=</span> <span class="n">disp_tensor</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_displacement_tensor</span></div>

<div class="viewcode-block" id="System.get_distance_matrix"><a class="viewcode-back" href="../../../doc/describe.core.html#describe.core.system.System.get_distance_matrix">[docs]</a>    <span class="k">def</span> <span class="nf">get_distance_matrix</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Calculates the distance matrix A defined as:</span>

<span class="sd">            A_ij = |r_i - r_j|</span>

<span class="sd">        For periodic systems the distance of an atom from itself is the</span>
<span class="sd">        smallest displacement of an atom from one of it&#39;s periodic copies, and</span>
<span class="sd">        the distance of two different atoms is the distance of two closest</span>
<span class="sd">        copies.</span>

<span class="sd">        Returns:</span>
<span class="sd">            np.array: Symmetric 2D matrix containing the pairwise distances.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_distance_matrix</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">displacement_tensor</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_displacement_tensor</span><span class="p">()</span>
            <span class="n">distance_matrix</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">displacement_tensor</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_distance_matrix</span> <span class="o">=</span> <span class="n">distance_matrix</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_distance_matrix</span></div>

<div class="viewcode-block" id="System.get_inverse_distance_matrix"><a class="viewcode-back" href="../../../doc/describe.core.html#describe.core.system.System.get_inverse_distance_matrix">[docs]</a>    <span class="k">def</span> <span class="nf">get_inverse_distance_matrix</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Calculates the inverse distance matrix A defined as:</span>

<span class="sd">            A_ij = 1/|r_i - r_j|</span>

<span class="sd">        For periodic systems the distance of an atom from itself is the</span>
<span class="sd">        smallest displacement of an atom from one of it&#39;s periodic copies, and</span>
<span class="sd">        the distance of two different atoms is the distance of two closest</span>
<span class="sd">        copies.</span>

<span class="sd">        Returns:</span>
<span class="sd">            np.array: Symmetric 2D matrix containing the pairwise inverse</span>
<span class="sd">            distances.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_inverse_distance_matrix</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">distance_matrix</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_distance_matrix</span><span class="p">()</span>
            <span class="k">with</span> <span class="n">np</span><span class="o">.</span><span class="n">errstate</span><span class="p">(</span><span class="n">divide</span><span class="o">=</span><span class="s1">&#39;ignore&#39;</span><span class="p">):</span>
                <span class="n">inv_distance_matrix</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">reciprocal</span><span class="p">(</span><span class="n">distance_matrix</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_inverse_distance_matrix</span> <span class="o">=</span> <span class="n">inv_distance_matrix</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_inverse_distance_matrix</span></div>

<div class="viewcode-block" id="System.set_positions"><a class="viewcode-back" href="../../../doc/describe.core.html#describe.core.system.System.set_positions">[docs]</a>    <span class="k">def</span> <span class="nf">set_positions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">newpositions</span><span class="p">,</span> <span class="n">apply_constraint</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_reset_structure</span><span class="p">()</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">set_positions</span><span class="p">(</span><span class="n">newpositions</span><span class="p">,</span> <span class="n">apply_constraint</span><span class="p">)</span></div>

<div class="viewcode-block" id="System.set_scaled_positions"><a class="viewcode-back" href="../../../doc/describe.core.html#describe.core.system.System.set_scaled_positions">[docs]</a>    <span class="k">def</span> <span class="nf">set_scaled_positions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">scaled</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_reset_structure</span><span class="p">()</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">set_scaled_positions</span><span class="p">(</span><span class="n">scaled</span><span class="p">)</span></div>

<div class="viewcode-block" id="System.set_pbc"><a class="viewcode-back" href="../../../doc/describe.core.html#describe.core.system.System.set_pbc">[docs]</a>    <span class="k">def</span> <span class="nf">set_pbc</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">pbc</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_reset_structure</span><span class="p">()</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">set_pbc</span><span class="p">(</span><span class="n">pbc</span><span class="p">)</span></div>

<div class="viewcode-block" id="System.set_cell"><a class="viewcode-back" href="../../../doc/describe.core.html#describe.core.system.System.set_cell">[docs]</a>    <span class="k">def</span> <span class="nf">set_cell</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cell</span><span class="p">,</span> <span class="n">scale_atoms</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_reset_structure</span><span class="p">()</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">set_cell</span><span class="p">(</span><span class="n">cell</span><span class="p">,</span> <span class="n">scale_atoms</span><span class="p">)</span></div>

    <span class="k">def</span> <span class="nf">_reset_structure</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Resets the common structural information that is cached by this</span>
<span class="sd">        object. The caching is done in order to share common structural</span>
<span class="sd">        quantities that are needed by multiple descriptors.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_cell_inverse</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_displacement_tensor</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_distance_matrix</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_inverse_distance_matrix</span> <span class="o">=</span> <span class="kc">None</span></div>
</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright .

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../../../',
            VERSION:'0.1.0',
            LANGUAGE:'None',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true,
            SOURCELINK_SUFFIX: '.txt'
        };
    </script>
      <script type="text/javascript" src="../../../_static/jquery.js"></script>
      <script type="text/javascript" src="../../../_static/underscore.js"></script>
      <script type="text/javascript" src="../../../_static/doctools.js"></script>
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

  

  <script type="text/javascript" src="../../../_static/js/theme.js"></script>

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>